/******************************************************************************
 * Copyright (C) 2017 Chengdu Dlhd information industry co. LTD.
 * All Rights Reserved.
 * 本软件为成都顶联互动信息产业有限公司开发研制。未经本公司正式书面同意，其他任何个人、团体不得使用、复制、修改或发布本软件.
 *****************************************************************************/
package net.dgg.dggcloud.service.jrcrm.service.call;

import net.dgg.dggcloud.core.minidao.hibernate.dao.IGenericBaseCommonDao;
import net.dgg.dggcloud.service.common.base.service.BaseService;
import net.dgg.dggcloud.service.entity.user.User;
import net.dgg.dggcloud.service.jrcrm.dao.customer.CallRecordDao;
import net.dgg.dggcloud.service.jrcrm.dao.customer.SoundCommentDao;
import net.dgg.dggcloud.service.jrcrm.entity.customer.CallRecord;
import net.dgg.dggcloud.service.jrcrm.entity.customer.SoundComment;
import org.apache.commons.collections.map.HashedMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 录音首页统计业务处理层
 * @ClassName: CallRecordPageAbilityService
 * @Author: 罗金
 * @Date: 2017年11月28 14:34:05
 * @Version V1.0
 */

@Service
public class CallRecordPageAbilityService extends BaseService {

    @Autowired
    private CallRecordDao callRecordDao;
    @Autowired
    private SoundCommentDao soundCommentDao;
    /**
     * 统计待听录音
     *
     * @param userIds 当前登录人id
     * @param orgIds  当前登录人部门ID
     * @return  paramMap
     */
    public Map<String,Object> callRecordPageCount(Map paramMap,String userIds,String orgIds){
        Map<String,Object> returnMap = new HashedMap();
        String type = null == paramMap.get("type") ? "" : paramMap.get("type").toString();
        String isListen = null == paramMap.get("isListen") ? "" : paramMap.get("isListen").toString();
        paramMap.put("userId",userIds);
        paramMap.put("orgId",orgIds);
        try {
            if(type.equals("isFirst")){//是否首电
                paramMap.put("isFirst",1);
                paramMap.put("isListen",0);
                int i = callRecordDao.callRecordCountPage(paramMap);//首电待听取录音
                returnMap.put("isFirst",i);
                paramMap.put("isListen",0);
                int j = callRecordDao.callRecordCountPage(paramMap);//推荐待听取录音
                returnMap.put("isnoListen",j);
            }
            if (type.equals("isListen")){ //是否待听取
                paramMap.put("isListen",0);
                paramMap.put("isListenValue",0);
                int i = callRecordDao.callRecordCountPage(paramMap);//推荐待听取录音
                returnMap.put("isnoListen",i);
                paramMap.put("isListen",1);
                paramMap.put("isListenValue",null);
                int  j = callRecordDao.callRecordCountPage(paramMap);//推荐待听取录音
                returnMap.put("isListen",j);
            }

            returnMap.put("message","操作成功");
            returnMap.put("result","0");
        } catch (Exception e) {
            returnMap.put("message","操作失败");
            returnMap.put("result","1");
        }
        return returnMap;
     }


    /**
     * 首电推荐待听录音
     *
     * @param userIds 当前登录人id
     * @param orgIds  当前登录人部门ID
     * @return  paramMap
     */
    public Map<String,Object> isFirstCallRecordPageCount(Map paramMap,String userIds,String orgIds){
        Map<String,Object> returnMap = new HashedMap();
        String type = null == paramMap.get("type") ? "" : paramMap.get("type").toString();
        String isListen = null == paramMap.get("isListen") ? "" : paramMap.get("isListen").toString();
        paramMap.put("userId",userIds);
        paramMap.put("orgId",orgIds);
        try {
            if(type.equals("isFirst")){//是否首电
                paramMap.put("isFirst",1);
                paramMap.put("isListen",0);
                int i = callRecordDao.callRecordCountPage(paramMap);//首电待听取录音
                returnMap.put("dataobject",i);
            }
            if (type.equals("isListen")){ //是否待听取
                paramMap.put("isListen",0);
                int i = callRecordDao.callRecordCountPage(paramMap);//推荐待听取录音
                returnMap.put("dataobject",i);
            }

            returnMap.put("message","操作成功");
            returnMap.put("result","0");
        } catch (Exception e) {
            returnMap.put("message","操作失败");
            returnMap.put("result","1");
        }
        return returnMap;
    }


    /**
     * 统计待听录音推送结束时间
     *
     * @param userIds 当前登录人id
     * @param orgIds  当前登录人部门ID
     * @return  paramMap
     */
    public Map<String,Object> callRecordPageCountEndTime(Map paramMap,String userIds,String orgIds){
        Map<String,Object> returnMap = new HashedMap();
        String type = null == paramMap.get("type") ? "" : paramMap.get("type").toString();
        String isListen = null == paramMap.get("isListen") ? "" : paramMap.get("isListen").toString();
        try {
            if(type.equals("isFirst")){//是否首电
                paramMap.put("isFirst",1);
                paramMap.put("isListen",0);
                Map timeMap = callRecordDao.callRecordCountPagePushEndTime(paramMap);
                returnMap.put("callCount",timeMap==null?"":timeMap.get("callCount"));
                returnMap.put("pushCycleEndTime",timeMap==null?"":timeMap.get("pushCycleEndTime"));
            }else if (type.equals("isListen")){ //是否待听取
                paramMap.put("isListen",0);
                Map timeMap = callRecordDao.callRecordCountPagePushEndTime(paramMap);
                returnMap.put("callCount",timeMap==null?"":timeMap.get("callCount"));
                returnMap.put("pushCycleEndTime",timeMap==null?"":timeMap.get("pushCycleEndTime"));
            }
            else if (type.equals("isListen")&&isListen.equals("1")){ //是否待听取
                paramMap.put("isListen",1);
                Map timeMap = callRecordDao.callRecordCountPagePushEndTime(paramMap);
                returnMap.put("callCount",timeMap==null?"":timeMap.get("callCount"));
                returnMap.put("pushCycleEndTime",timeMap==null?"":timeMap.get("pushCycleEndTime"));
            }
            returnMap.put("message","操作成功");
            returnMap.put("result","0");
        } catch (Exception e) {
            returnMap.put("message","操作失败");
            returnMap.put("result","1");
        }
        return returnMap;
    }

}
